package com.honey.compilation.xml;

import com.honey.core.builder.CharacterBuilder;
import com.honey.core.builder.CharacterBuilderFactory;
import com.honey.core.compiler.IndentSpace;

/**
 * CDATA 块 <![CDATA[文本内容]]>
 * 
 * @author Administrator
 * 
 */
public class CDATAElement extends TextElement {
	
	/**
	 * 构造函数
	 */
	public CDATAElement(){
		super();
	}
	
	/**
	 * 构造函数
	 * @param contents 文本内容
	 */
	public CDATAElement(String ...contents) {
		super(contents);

	}
	
	@Override
	public CharacterBuilder compiledContent(int indentLevel) {
		CharacterBuilder answer = CharacterBuilderFactory.createC16StringBuilder();
		
		IndentSpace.spaceIndent(answer, indentLevel);
		answer.append("<![CDATA[ ");
		if(getContents() .size() > 1){
			indentLevel ++;
			IndentSpace.newLine(answer);
			for(String content : getContents()){
				IndentSpace.spaceIndent(answer, indentLevel);
				answer.append(content);
				IndentSpace.newLine(answer);
			}
			indentLevel --;
			IndentSpace.spaceIndent(answer, indentLevel);
		}else{
			answer.append(getContents().get(0));
		}
		answer.append(" ]]>");
		
		return answer;
	}
}
